import java.util.Arrays;

public class quecksort1 {//双面扫描

    public static void quicksort1(int[] arr, int b, int e) {//b为初始，e为终止
        if (b < e) {
            int q = seachersort1(arr, b, e);
            quicksort1(arr, q + 1, e);
            quicksort1(arr, b, q - 1);
        }
    }

    public static int seachersort1(int[] arr, int b, int e) {
        int pivot = arr[b];
        int left = b + 1;
        int right = e;
        while (left <= right) {
            while (left <= right && arr[left] <= pivot) {
                left++;
            }
            while (left <= right && arr[right] > pivot) {
                right--;
            }
                    if(left<right) {
                        int index = arr[left];
                        arr[left] = arr[right];
                        arr[right] = index;
                    }
            }

        int indec = arr[right];
        arr[right] = pivot;
        arr[b] = indec;
        return right;
    }

    public static void main(String args[]) {
        int[] arr = {2, 34, 5, 7, 56, 99, 71, 11, 32};
        quicksort1(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }
}